(function(fruit,util){
    /**
     * @link http://webstuff.nfshost.com/anim-timing/Overview.html
     * @link https://developer.mozilla.org/en/DOM/window.requestAnimationFrame
     * @link http://dev.chromium.org/developers/design-documents/requestanimationframe-implementation
     */
    var requestAnimationFrame = ( function()
    {
        return window.requestAnimationFrame
            || window.webkitRequestAnimationFrame
            || window.mozRequestAnimationFrame
            || window.oRequestAnimationFrame
            || window.msRequestAnimationFrame
            || function( callback )
        {return window.setTimeout( callback, 1000 / 60 );};
    })(), cancelAnimationFrame = ( function()
    {
        return window.cancelAnimationFrame
            || window.cancelRequestAnimationFrame
            || window.webkitCancelAnimationFrame
            || window.webkitCancelRequestAnimationFrame
            || window.mozCancelAnimationFrame
            || window.mozCancelRequestAnimationFrame
            || window.msCancelAnimationFrame
            || window.msCancelRequestAnimationFrame
            || window.oCancelAnimationFrame
            || window.oCancelRequestAnimationFrame
            || window.clearTimeout;
    })();

    function createAnimation(callback,duration,interval){
        var startTime,progress, id,progress,timestamp, lastTime = 0;
        function fn(){
            timestamp = +new Date();

            if(!startTime){
                startTime = +new Date();
                progress = 0;
            }else{
                if(!duration){
                    progress = 0;
                }else{
                    progress = (timestamp-startTime)/duration;
                }
            }
            if(progress>=1 || (timestamp - lastTime)>=interval){
                lastTime = timestamp;
                if(progress>1){
                    progress = 1
                }
               if(callback(progress)===false){
                   //break  when user return false
                   duration =1;
               }

            }
            if(progress<1){
                id = requestAnimationFrame(fn);
            }
        }
        return {
            start:function(){
                id = requestAnimationFrame(fn)
            },
            stop:function(){
                cancelAnimationFrame(id);
            }
        }
    }
    fruit.define('fruit.util.Animation',{
        singleton:true,
        methods:{
            init:function(){
                this._pool ={};
            },
            create:function(fn,duration,interval){
                return createAnimation(fn,duration,interval);
            }
        }
    })
})(fruit,fruit.util);